//
//  ZJDesThirdTravelTableViewCell.m
//  BreadTravel
//
//  Created by 张健 on 15/12/24.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ZJDesThirdTravelTableViewCell.h"

@implementation ZJDesThirdTravelTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}

- (void)creatView{
    
    self.bgView = [[UIView alloc]init];
    self.bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.and.left.mas_equalTo(10);
        make.width.mas_equalTo(WIDTH-20);
        make.height.mas_equalTo(110);
    }];
    
    self.cover_s = [[UIImageView alloc]init];
    [self.bgView addSubview:self.cover_s];
    [self.cover_s mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.and.left.mas_equalTo(10);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(90);
    }];
    
    self.name = [[UILabel alloc]init];
    [self.bgView addSubview:self.name];
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.cover_s.mas_right).offset(10);
        make.top.equalTo(self.cover_s.mas_top).offset(3);
        make.right.mas_equalTo(-50);
    }];
    
//    /**********评分星星***********/
//    UIImageView *imageView1 = [[UIImageView alloc]init];
//    imageView1.image = [UIImage imageNamed:@"rating_gray@2x.png"];
//    [self.bgView addSubview:imageView1];
//    [imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.equalTo(self.name);
//        make.top.equalTo(self.name.mas_bottom).offset(1);
//        make.width.mas_equalTo(100);
//        make.height.mas_equalTo(18);
//    }];
//    float A = [self.rating floatValue];
//    float bi = A / 5.0;
//    UIImageView *imageTemp2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"rating"]];
//    UIImage  *image1  = [UIImage imageNamed:@"rating@2x.png"];
//    
//    CGImageRef imageRef  = image1.CGImage;
//    
//    CGImageRef image2 = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0, imageTemp2.frame.size.width*bi*2, imageTemp2.frame.size.height*2));
//    
//    UIImageView *imageView2 = [[UIImageView alloc]init];
//    imageView2.frame = CGRectMake(0, 0, imageView1.frame.size.width * bi, imageView1.frame.size.height);
//    imageView2.image = [UIImage imageWithCGImage:image2];
//    
//    [imageView1 addSubview:imageView2];
//    //*********评分星星**********
    
//    self.tips_count = [[UILabel alloc]init];
//    self.tips_count.backgroundColor = [UIColor grayColor];
//    self.tips_count.font = [UIFont systemFontOfSize:12];
//    [self.bgView addSubview:self.tips_count];
//    [self.tips_count mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.equalTo(imageView1.mas_right).offset(10);
//        make.top.equalTo(imageView1);
//        make.width.mas_equalTo(50);
//        make.height.mas_equalTo(15);
//    }];
    
    self.visited_count = [[UILabel alloc]init];
    self.visited_count.font = [UIFont systemFontOfSize:12];
    [self.bgView addSubview:self.visited_count];
    [self.visited_count mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.equalTo(self.cover_s.mas_bottom).offset(-2);
        make.left.equalTo(self.name);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(15);
    }];
}

-(void)setPlaceModel:(ZJDesThirdTravelModel *)placeModel{
    
    if ([placeModel.recommended_reason isEqualToString:@""]) {
        
        [self.recommended_reason removeFromSuperview];

        self.content = [[UILabel alloc]init];
        self.content.numberOfLines = 0;
        self.content.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.content];
        self.content.text = placeModel.description1;
        [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.name);
            make.top.equalTo(self.name.mas_bottom).offset(20);
            make.width.mas_equalTo(WIDTH-150);
            make.height.mas_equalTo(35);
        }];
        
        
    }else{
        [self.content removeFromSuperview];
        
        self.recommended_reason = [[UILabel alloc]init];
        self.recommended_reason.numberOfLines = 0;
        self.recommended_reason.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.recommended_reason];
        [self.recommended_reason mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.name);
            make.top.equalTo(self.name.mas_bottom).offset(20);
            make.width.mas_equalTo(WIDTH-150);
            make.height.mas_equalTo(35);
        }];
    }
    
    NSURL *url = [NSURL URLWithString:placeModel.cover_s];
    [self.cover_s sd_setImageWithURL:url placeholderImage:IMAGE];
    
    self.name.text = placeModel.name;
    self.visited_count.text = [NSString stringWithFormat:@"%@  人去过",placeModel.visited_count];
    self.rating = placeModel.rating;
    self.recommended_reason.text = placeModel.recommended_reason;
    
    
    /**********评分星星***********/
    UIImageView *imageView1 = [[UIImageView alloc]init];
//    imageView1.frame = CGRectMake(self.visited_count.X+self.cover_s.frame.size.width   , self.name.Y+self.name.H+1, 100, 18);
    [self.bgView addSubview:imageView1];
    [imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.name);
        make.top.equalTo(self.name.mas_bottom).offset(1);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(18);
    }];
    imageView1.image = [UIImage imageNamed:@"rating_gray@2x.png"];
    self.rating = placeModel.rating;
    float A = [self.rating floatValue];
    float bi = A / 5.0;
    UIImageView *imageTemp2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"rating"]];
    UIImage  *image1  = [UIImage imageNamed:@"rating@2x.png"];
    
    CGImageRef imageRef  = image1.CGImage;
    
    CGImageRef image2 = CGImageCreateWithImageInRect(imageRef, CGRectMake(0, 0, imageTemp2.frame.size.width*bi*2, imageTemp2.frame.size.height*2));
    
    UIImageView *imageView2 = [[UIImageView alloc]init];
    imageView2.frame = CGRectMake(0, 0, imageView1.frame.size.width * bi, imageView1.frame.size.height);
    imageView2.image = [UIImage imageWithCGImage:image2];
    
    [imageView1 addSubview:imageView2];
//    [imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.top.and.left.mas_equalTo(0);
//        make.width.mas_equalTo(imageView1.frame.size.width * bi);
//        make.height.equalTo(imageView1);
//    }];
    //*********评分星星**********
    
    
}





@end
